<template>
  <div class="wrapper">
    <el-table :data="nodeList" class="table" @row-click="goNodeInfo">
      <el-table-column prop="title" label="标题"></el-table-column>
      <el-table-column prop="category" label="类别"></el-table-column>
      <el-table-column prop="author" label="LOVE"></el-table-column>
      <el-table-column prop="createTime" label="创建时间"></el-table-column>
    </el-table>
  </div>
</template>

<script>
import * as NodeApi from '../../api/node'
import {fmtDate2} from '../../utils/DateUtil'

export default {
  name: 'index',
  data() {
    return {
      nodeList: []
    }
  },
  created() {
    this.getNode()
  },
  methods: {
    getNode() {
      NodeApi.getNode().then(rep => {
        console.log(rep)
        rep.data.forEach(item => {
          item.createTime = fmtDate2(item.createTime)
        })
        this.nodeList = rep.data
        console.log(this.nodeList)
      })
    },
    goCreate() {
      this.$router.push({name: 'NodeCreate'})
    },
    goNodeInfo(row) {
      console.log(row)
      this.$router.push({name: 'NodeInfo', query: {id: row.id}})
    }
  }
}
</script>

<style scoped>
.wrapper {
  padding: 20px;
}
.table {
  cursor: pointer;
}
.row {
  margin: 10px;
}
</style>
